var bigCata = [{
	"status":"200",
	"info":[
	{
		"id": "1100",
		"name": "计算机(IT)类",
		"parentID": "0",
		"child":"1"
	},{
		"id": "2000",
		"name": "计算机(IT)类2",
		"parentID": "0",
		"child":"1"
	}]
}];
var cata = [{
	"status":"200",
	"info":[
	{
		"id": "1101",
		"name": "技术总监/CTO",
		"parentID": "1100",
		"child":"1"
	},{
		"id": "1201",
		"name": "信息主管/CIO",
		"parentID": "1100",
		"child":"0"
	}]
}];
var cata2 = [{
	"status":"200",
	"info":[
	{
		"id": "2101",
		"name": "技术总监/CTO2",
		"parentID": "2000",
		"child":"0"
	},{
		"id": "2201",
		"name": "信息主管/CIO2",
		"parentID": "2000",
		"child":"0"
	}]
}];
var smallCate = [{
	"status":"200",
	"info":[
	{
		"id": "1111",
		"name": "技术总监/php",
		"parentID": "1101",
		"child":"0"
	},
	{
		"id": "1112",
		"name": "技术总监/java",
		"parentID": "1101",
		"child":"0"
	},
	{
		"id": "1113",
		"name": "技术总监/js",
		"parentID": "1101",
		"child":"0"
	}]
}];

$("#btnWishTrade").click(function(){
	//console.log(bigCata);
	var html = "<ul>";
	for(var i=0;i<bigCata[0].info.length;i++){
		html += "<li class='bigcata' data="+bigCata[0].info[i].id+" style='cursor: pointer;' ><label>"+bigCata[0].info[i].name+"</label></li>";
	}
	html +="</ul>";
	$(".choiceLst").html(html);
	$("._btnAreaClear").attr("data",1);
	
	//获取选中的值
	var ids = $("#calling").val();
	if(ids){
		var cataArr = getString(ids,",");
		var cataNames = $(".callinghtml").html();
		var cataNameArr = getString(cataNames,",");
		var choice = '';
		for(var i=0;i<cataArr.length;i++){
			choice += '<li class="'+cataArr[i]+'"><label><input type="checkbox" class="popChkdel" data="'+cataNameArr[i]+'" value="'+cataArr[i]+'" checked="checked">'+cataNameArr[i]+'</label></li>';
		}
	}
	$("#_selected").append(choice);
	
	$(".dialogMask,.choice").show();
})
$(document).on("click", ".bigcata", function(){
	$(".cateul,.smallcateul").remove();
	var id = $(this).attr("data");//根据id去请求子类  假如得到的子类为cata
	if(id!=1100){
		return ;
	}
	//console.log(cata);
	//console.log(getCalling(id));
	//var cata = getCalling(id);
	//if(cata.hasOwnProperty('subSorts')){
		var html = "<ul class='cateul'>";
		var ids = $("#calling").val();
		var cataArr = getString(ids,",");
		for(var i=0;i<cata[0].info.length;i++){
			if(cata[0].info[i].child != 0){
				html += "<li class='cata' data="+cata[0].info[i].id+" style='cursor: pointer;' ><label>"+cata[0].info[i].name+"</label></li>";
			}else{
				if($.inArray(cata[0].info[i].id, cataArr)==-1){
					var check='';
				}else{
					var check='checked="checked"';
				}
				html += "<li class='cata' data="+cata[0].info[i].id+" style='cursor: pointer;' ><label><input type='checkbox' class='popChk cata_"+cata[0].info[i].id+"' name='cata' "+check+" data_name="+cata[0].info[i].name+" value="+cata[0].info[i].id+" >"+cata[0].info[i].name+"</label></li>";
			}
		}
		html +="</ul>";
		$(".choiceLst").append(html);
	//}
});
$(document).on("click", ".cata", function(){
	$(".smallcateul").remove();
	var id = $(this).attr("data");//根据id去请求子类  假如得到的子类为smallCata
	if(id!=1101){
		return ;
	}
	//console.log(getCalling(id));
	//var cata = getCalling(id);
	//if(cata.hasOwnProperty('subSorts')){
		var html = "<ul class='smallcateul'>";
		var ids = $("#calling").val();
		var cataArr = getString(ids,",");
		for(var i=0;i<smallCate[0].info.length;i++){
			if(smallCate[0].info[i].child != 0){
				html += "<li class='smallcata' data="+smallCate[0].info[i].id+" style='cursor: pointer;' ><label>"+smallCate[0].info[i].name+"</label></li>";
			}else{
				if($.inArray(smallCate[0].info[i].id, cataArr)==-1){
					var check='';
				}else{
					var check='checked="checked"';
				}
				html += "<li class='smallcata' data="+smallCate[0].info[i].id+" style='cursor: pointer;' ><label><input type='checkbox'  class='popChk cata_"+smallCate[0].info[i].id+"' name='smallcata' "+check+" data_name="+smallCate[0].info[i].name+" value="+smallCate[0].info[i].id+">"+smallCate[0].info[i].name+"</label></li>";
			}
		}
		html +="</ul>";
		$(".choiceLst").append(html);
	//}
}); 

$(document).on("click", ".popChk", function(){
	var ids = $("#calling").val();
	//console.log($(this).val());
	var id = $(this).val();
	//console.log($(this).attr("data_name"));
	var cataName = $(this).attr("data_name");
	var cataNames = $(".callinghtml").html();
	if($(this).prop("checked")){
		if(ids){
			var cataArr = getString(ids,",");
			cataArr = addKey(cataArr,id);
			if(!cataArr){
				return false;
			}
			$("#calling").val(cataArr.join());
			
			var cataHtmlArr = getString(cataNames,",");
			cataHtmlArr = addKey(cataHtmlArr,cataName);
			$(".callinghtml").html(cataHtmlArr.join());
		}else{
			$("#calling").val(id);
			$(".callinghtml").html(cataName);
		}
		$("#_selected").append('<li class="'+id+'"><label><input type="checkbox" class="popChkdel" data="'+cataName+'" value="'+id+'" checked="checked">'+cataName+'</label></li>');
	}else{
		var cataArr = getString(ids,",");
		cataArr = delkey(cataArr,id);
		$("."+id).remove();
		$("#calling").val(cataArr.join());
		
		var cataHtmlArr = getString(cataNames,",");
		cataHtmlArr = delkey(cataHtmlArr,cataName);
		if(cataHtmlArr.join()==''){
			$(".callinghtml").html("请选择");
		}else{
			$(".callinghtml").html(cataHtmlArr.join());
		}
	}
})
$(document).on("click", ".popChkdel", function(){
	var id = $(this).val();
	var cataName = $(this).attr("data");
	var ids = $("#calling").val();
	var cataArr = getString(ids,",");
	cataArr = delkey(cataArr,id);
	$("."+id).remove();
	$("#calling").val(cataArr.join());
	$(".cata_"+id).attr("checked",false);
	
	var cataNames = $(".callinghtml").html();
	var cataHtmlArr = getString(cataNames,",");
	cataHtmlArr = delkey(cataHtmlArr,cataName);
	if(cataHtmlArr.join()==''){
		$(".callinghtml").html("请选择");
	}else{
		$(".callinghtml").html(cataHtmlArr.join());
	}
	
})